#include "ServerMessageReceiver.h"
#include "NetworkEvent.h"
#include "ClientConnectNetworkEvent.h"
#include "NetworkException.h"
#include "NetworkWrapper.h"
#include "EventWrapper.h"

ServerMessageReceiver::ServerMessageReceiver(const TCPsocket& socket, int id)
        : MessageReceiver(socket), id(id)
{
}

ServerMessageReceiver::~ServerMessageReceiver()
{
}

void ServerMessageReceiver::init()
{
}

void ServerMessageReceiver::pushEvent(NetworkEvent::Header& header, void* data)
{
    NetworkEvent::Header* h = NetworkEvent::allocateHeader(header.code, id);
    EventWrapper::push(h, data);
}

void* ServerMessageReceiver::createDisconnectEvent(NetworkEvent::Header& header)
{
    header.code = NetworkEvent::CLIENT_DISCONNECTED;
    header.sizeOfData = sizeof(int);
    void* data = malloc(sizeof(int));
    (*(int*)(data)) = id;
    return data;
}

